import { getUserByRoleId,sysAddRole,sysGetRoles,sysUpdateRole,newSysDelRole,getRoleByStatusOrCreateBy,newsysgetRolesByCreateUser,getRolesByCreateUser,getRoleByStatusOrCreateByPage } from '@/services/overviewRobots';

export default {
  namespace: 'roleManagement',

  state: {
   
  },
  effects: {
    *getUserByRoleId({ payload, callback }, { call, put }) { // 添加角色
      const response = yield call(getUserByRoleId, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *sysAddRole({ payload, callback }, { call, put }) { // 添加角色
      const response = yield call(sysAddRole, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *sysGetRoles({ payload, callback }, { call, put }) { // 通过id查询角色列表
      const response = yield call(sysGetRoles, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *sysUpdateRole({ payload, callback }, { call, put }) { // 编辑角色
      const response = yield call(sysUpdateRole, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *newSysDelRole({ payload, callback }, { call, put }) { // 删除角色
      const response = yield call(newSysDelRole, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRoleByStatusOrCreateBy({ payload, callback }, { call, put }) { // 删除角色
      const response = yield call(getRoleByStatusOrCreateBy, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *newsysgetRolesByCreateUser({ payload, callback }, { call, put }) { // 初始化列表
      const response = yield call(newsysgetRolesByCreateUser, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRolesByCreateUser({ payload, callback }, { call, put }) { // 删除角色
      const response = yield call(getRolesByCreateUser, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
    *getRoleByStatusOrCreateByPage({ payload, callback }, { call, put }) { // 删除角色
      const response = yield call(getRoleByStatusOrCreateByPage, payload);
      if (response) {
        if (callback && typeof callback === 'function') {
          callback(response);
        }
        yield put({
          type: 'save',
          payload: response,
        });
      }
    },
  },

  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
    fetchb(state,{payload}){
      return {
        ...state,
        ...payload,
      };
    },
    clear() {
      return {
        total:'',
        list:[]
      };
    },
  },
};
